
** Replication code for Higashijima, Masaaki and Yujin Woo. "Political Regimes and Refugee Entries: The Preferences and Decisions of Displaced Persons and Host Governments." International Studies Quarterly 

* Figure 1
egen sum_refugee = sum(total_refugee), by(a_year) 
graph twoway line sum_refugee a_year if ccode==2 & a_year>=1951 & a_year<=2016

* Figure 2

drop ave_polity2 ave_vdem_polyarchy100
egen ave_polity2 = mean(polity2_v_recode2), by(ccode)
egen ave_vdem_polyarchy100 = mean(vdem_polyarchy100), by(ccode)

* outcome
drop ave_log_refugee
egen ave_log_refugee = mean(log_refugee), by(ccode)

drop polity2_pred refugee_pred vdem_polyarchy100_pred

reg polity2 log_gdp population_combined if a_year==2000
predict polity2_pred, residuals

reg log_refugee log_gdp population_combined if a_year==2000
predict refugee_pred, residuals

* Left in Figure 2
lowess refugee_pred polity2_pred if a_year==2000

reg vdem_polyarchy100 log_gdp population_combined if a_year==2000
predict vdem_polyarchy100_pred, residuals

* Right in Figure 2
lowess refugee_pred vdem_polyarchy100_pred if a_year==2000


* Model 1 (without controls)
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2 i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

* Descriptive statistics (shown in appendix a)

#delimit 
summarize total_refugee polity2_v_recode2 vdem_polyarchy100 log_gdp_maddison conflict_ucdp2016 growth_maddison 
log_n_refugee polity2_v_neighbor polyarchy100_neighbor
log_neighbor_bd_merge neighbor_neighbor_cd
apply_total recognize_total reject_total if e(sample); 

#delimit cr; 


* Model 2 (with controls)

#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
* compute BIC
estat ic

* Upper-left in Figure 3
margins, at(polity2_v_recode2=(0 (1) 20)) atmeans  
marginsplot, title ("POLITY (Monad)", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram polity2_v_recode2 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  xlabel(none) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line)	


* Model 3(with controls)  

#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic


* Upper-right in Figure 3
margins, at(vdem_polyarchy100 =(0 (5) 100)) atmeans
marginsplot, title ("V-Dem (Monad)", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram vdem_polyarchy100 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  xlabel(none) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line)	


******* Models of refugee applications
* Presentations of full models are available in Appendix B5

* Model 7 (with Polity and without controls)
#delimit 
xtnbreg apply_total polity2_v_recode2
i.a_year, pa force corr(ar1) vce(robust) exposure(population_combined) ;

#delimit cr;


*** Model 8 (Polity and with controls)

#delimit 
xtnbreg apply_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
 i.a_year, pa force corr(ar1) vce(robust) exposure(population_combined);

#delimit cr;

* Left in Figure 4
margins, at(polity2_v_recode=(0 (1) 20)) atmeans
marginsplot, title ("POLITY", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram polity2_v_recode2 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  xlabel(none) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line)	


#delimit cr;

*Model 9 (Vdem with controls) 

#delimit 
xtnbreg apply_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, pa corr(ar1) force vce(robust) exposure(population_combined);

#delimit cr;

* Right in Figure 4
margins, at(vdem_polyarchy100=(0 (10) 100)) atmeans
marginsplot, title ("V-DEM", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram vdem_polyarchy100 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  xlabel(none) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line)	
 

************* Government's Acceptance of Refugee Applications ***************
* Presentations of full models are available in Appendix B5

* Model 10
#delimit 
nbreg recognize_total polity2_v_recode2
i.a_year, cluster(ccode) exposure(apply_total2);

#delimit cr;

* Model 11

#delimit 
nbreg recognize_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.a_year, cluster(ccode) exposure(apply_total2);

#delimit cr;

* Left in Figure 5
margins, at(polity2_v_recode=(0 (1) 20)) atmeans
marginsplot, title ("POLITY", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram polity2_v_recode2 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  xlabel(none) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line)	

* Model 12
#delimit 
nbreg recognize_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, cluster(ccode) exposure(apply_total2);

#delimit cr;

* Right in Figure 5
margins, at(vdem_polyarchy100=(0 (10) 100)) atmeans
marginsplot, title ("V-DEM", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram vdem_polyarchy100 if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  xlabel(none) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line)	

* Model 13
#delimit 
nbreg reject_total polity2_v_recode2
i.a_year, cluster(ccode) exposure(apply_total2);

#delimit cr;

* Model 14
#delimit 
nbreg reject_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.a_year, cluster(ccode) exposure(apply_total2);

#delimit cr;

* Model 15
#delimit 
nbreg reject_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, cluster(ccode) exposure(apply_total2);

#delimit cr;

*************** Robustness Check **********************


** Appendix B2

** (1) FE-OLS with clustered SD

* Model B2-1
#delimit 
reg log_refugee l.log_refugee c.polity2_v_recode2##c.polity2_v_recode2
i.ccode i.a_year, cluster(ccode) ;

#delimit cr;

* Model B2-2
#delimit 
reg log_refugee l.log_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) ;

#delimit cr;

* Model B2-3
#delimit 
reg log_refugee l.log_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) ;

#delimit cr;

* (2) FE-OLS with DK standard errors

* Model B2-4
#delimit 
xtscc log_refugee l.log_refugee c.polity2_v_recode2##c.polity2_v_recode2
i.a_year, fe lag(2) ;

#delimit cr;


* Model B2-5
#delimit 
xtscc log_refugee l.log_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp growth_maddison
i.a_year, fe lag(2) ;

#delimit cr;

* Model B2-6
#delimit 
xtscc log_refugee l.log_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, fe lag(2) ;

#delimit cr;

* (3) Generalized Estimating Equations with AR (1) 

* Model B2-7
#delimit
xtgee total_refugee c.polity2_v_recode2##c.polity2_v_recode2
i.a_year, force family(nbinomial) link(log) vce(robust) corr(ar1) exposure(population_combined) iterate(100);

#delimit cr;

* Model B2-8

* recoded polity could not yield the results
#delimit
xtgee total_refugee c.polity2##c.polity2
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.ccode
i.a_year, force family(nbinomial) link(log) vce(robust) corr(ar1) exposure(population_combined) iterate(100);

#delimit cr;


* Model B2-9
#delimit 
xtgee total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_gdp_maddison log_neighbor_bd_merge log_neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison i.ccode
i.a_year, force family(nbinomial) link(log) vce(robust) corr(ar1) exposure(population_combined) iterate(100);

#delimit cr;


** Appendix B3 

* (1) lag (up to 3 years)

* Model B3-1
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2 c.l.polity2_v_recode2##c.l.polity2_v_recode2 c.l2.polity2_v_recode2##c.l2.polity2_v_recode2 c.l3.polity2_v_recode2##c.l3.polity2_v_recode2
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

* Model B3-2
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2 c.l.polity2_v_recode2##c.l.polity2_v_recode2 c.l2.polity2_v_recode2##c.l2.polity2_v_recode2 c.l3.polity2_v_recode2##c.l3.polity2_v_recode2
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

* Model B3-3
#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100 c.l.vdem_polyarchy100##c.l.vdem_polyarchy100 c.l2.vdem_polyarchy100##c.l2.vdem_polyarchy100 c.l3.vdem_polyarchy100##c.l3.vdem_polyarchy100
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic


* (2) xpolity

* Model B3-2-1 (without controls)
#delimit 
nbreg total_refugee c.xpolity_v##c.xpolity_v i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

* Model B3-2-2 (with controls)

#delimit 
nbreg total_refugee c.xpolity_v##c.xpolity_v
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

** Appendix B6

** Application
* Model B6-1
#delimit 
xtnbreg apply_total polity2_v_recode2
 i.a_year, re exposure(population_combined) ;

#delimit cr;

* Model B6-2

#delimit 
xtnbreg apply_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.a_year, re exposure(population_combined);

#delimit cr;

* Model B6-3
#delimit 
xtnbreg apply_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, re exposure(population_combined);

#delimit cr;


** Appendix B7

** Recognition


* Model B7-1
#delimit 
xtreg recognize_pro2 l_recognize_pro2 polity2_v_recode2
i.a_year, re;

#delimit cr; 
 
* Model B7-2
#delimit 
xtreg recognize_pro2 l_recognize_pro2 polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.a_year, re;

#delimit cr;

* Model B7-3
#delimit 
xtreg recognize_pro2 l_recognize_pro2 vdem_polyarchy100  log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, re;

#delimit cr;


** Rejection


* Model B7-4
#delimit 
xtreg reject_pro2 l_reject_pro2 polity2_v_recode2 
i.a_year, re;

#delimit cr;

* Model B7-5
#delimit 
xtreg reject_pro2 l_reject_pro2 polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison 
i.a_year, re;

#delimit cr;

* Model B7-6
#delimit 
xtreg reject_pro2 l_reject_pro2 vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year, re ;

#delimit cr;

 
** Appendix B8
** controlling for immigration/refugee policy 

** Model B8-1: control for impic (refugee) + polity 
#delimit 
nbreg total_refugee polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
l.impic_refugee
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;

** Model B8-2: polity + limited sample with impic 
#delimit 
nbreg total_refugee c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year if impic_refugee!=., cluster(ccode) exposure(population_combined);

#delimit cr;

** Model B8-3: impic (refugee) + vdem
#delimit 
nbreg total_refugee vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
l.impic_refugee
i.ccode, cluster(ccode) exposure(population_combined);

#delimit cr;

** Model B8-4: vdem + limited sample with impic (refugee) 
#delimit 
nbreg total_refugee vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year if l.impic_refugee!=., cluster(ccode) exposure(population_combined);

#delimit cr;


** Model B8-5: control for dwrap + polity 
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
l.dwrap
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;

** Model B8-6: polity + limited sample with dwrap 
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year if l.dwrap!=., cluster(ccode) exposure(population_combined);

#delimit cr;

** Model B8-7: control for dwrap + vdem 
#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
dwrap
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;

** Model B8-8: vdem + limited sample with dwrap 
#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year if dwrap!=., cluster(ccode) exposure(population_combined);

#delimit cr;


* recognition 

** Model B8-9: control for impic (refugee) + polity 
#delimit 
nbreg recognize_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
l.impic_refugee
i.a_year i.ccode, cluster(ccode) exposure(apply_total2);

#delimit cr;

**  Model B8-10: polity + limited sample with impic 
#delimit 
nbreg recognize_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.a_year i.ccode if l.impic_refugee!=., cluster(ccode) exposure(apply_total2);

#delimit cr;


**  Model B8-11: impic (refugee) + vdem
#delimit 
nbreg recognize_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
l.impic_refugee
i.a_year i.ccode, cluster(ccode) exposure(apply_total2);

#delimit cr;

**  Model B8-12: vdem + limited sample with impic (refugee) 
#delimit 
nbreg recognize_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year i.ccode if l.impic_refugee!=., cluster(ccode) exposure(apply_total2);

#delimit cr;


* dwrap 

**  Model B8-13: control for dwrap + polity 
#delimit 
nbreg recognize_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
l.dwrap
i.a_year i.ccode, cluster(ccode) exposure(apply_total2);

#delimit cr;

**  Model B8-14: polity + limited sample with dwrap 
#delimit 
nbreg recognize_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.a_year i.ccode if l.dwrap!=., cluster(ccode) exposure(apply_total2);

#delimit cr;

**  Model B8-15: control for dwrap + vdem 
#delimit 
nbreg recognize_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
l.dwrap i.a_year i.ccode, cluster(ccode) exposure(apply_total2);

#delimit cr;

**  Model B8-16: vdem + limited sample with dwrap 
#delimit 
nbreg recognize_total vdem_polyarchy100 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.a_year i.ccode if l.dwrap!=., cluster(ccode) exposure(apply_total2);

#delimit cr;


** Appendix B9
** oil issue

** exclude oil-producing countries (90th percentile)

* Model B9-1
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year 
if log_oil<6.5, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

* Model B9-2
#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year 
if log_oil<6.5, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

** control

* Model B9-3
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
log_oil
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

* Model B9-4
#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
log_oil
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;
estat ic

** conditional effects


#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2##c.log_oil
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;

* Figure B9-1
margins,  at (polity2_v_recode2=(0(1)20) log_oil==(0(6.5)6.5)) atmeans
			marginsplot, title ("Predicted SWD", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram diff_both_2tr if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off)) ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line) 
			


#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100##c.log_oil
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;

* Figure B9-2
margins,  at (vdem_polyarchy100=(0(5)100) log_oil==(0(6.5)6.5)) atmeans
			marginsplot, title ("V-Dem", color(black)) graphregion(fcolor(white)) plotregion(fcolor(white)) addplot(histogram diff_both_2tr if e(sample)==1, fcolor(none) lcolor(gs11) yscale(alt) yaxis(2) legend(off))  ciopts(lcolor(black) lpattern(dash)) recastci(rline) recast(line) xscale(0(5)20)	
			graph save Fig1c, replace


** Appendix B10
**control for state capacity (v2svstterr)

* Model B10-1
#delimit 
nbreg total_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison c.v2svstterr##c.v2svstterr
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;

* Model B10-2
#delimit 
nbreg total_refugee c.vdem_polyarchy100##c.vdem_polyarchy100
log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor 
log_gdp_maddison conflict_ucdp2016 growth_maddison c.v2svstterr##c.v2svstterr
i.ccode i.a_year, cluster(ccode) exposure(population_combined);

#delimit cr;


** jackknife analysis for acceptance and application


** refugee entries 

** (i) country

set scrollbufsize 300000

forval i=1/159 {
reg log_refugee l.log_refugee c.polity2_v_recode2##c.polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd  log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.ccode i.a_year if country_id!=`i', cluster(ccode) 
} 

** (ii) time period

forval i=1/72 {
reg log_refugee l.log_refugee c.polity2_v_recode2##c.polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd  log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.ccode i.a_year if year_id!=`i', cluster(ccode) 
} 

** refugee acceptance
* (i) country
forval i=1/159 {
xtgee recognize_pro2 polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.a_year if country_id!=`i', force link(log) corr(ar 1) vce(robust)
} 

* (ii) time period

forval i=1/72 {
xtgee recognize_pro2 polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.a_year if year_id!=`i', force link(log) corr(ar 1) vce(robust) 
} 

** refugee application 
* (i) country
forval i=1/159 {
xtnbreg apply_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.a_year if country_id!=`i', pa force corr(ar1) vce(robust) exposure(population_combined)
} 

* time period
forval i=1/72 {
xtnbreg apply_total polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison i.a_year if year_id!=`i', pa force corr(ar1) vce(robust) exposure(population_combined)
} 
 
** Appendix B4 multiple imputation 

mi set wide
mi register imputed log_refugee
mi impute mvn log_refugee = polity2_v_recode2 log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd  log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison if a_year>=1951 & a_year<=2016, add(5) replace force

* Model B4-1
#delimit 
mi estimate, post : reg log_refugee c.polity2_v_recode2##c.polity2_v_recode2
i.ccode i.a_year, cluster(ccode) ; 
#delimit cr;  


* Model B4-2
#delimit 
mi estimate, post : reg log_refugee c.polity2_v_recode2##c.polity2_v_recode2
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polity2_v_neighbor conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) ; 
#delimit cr; 


* Model B4-3
#delimit 
mi estimate, post : reg log_refugee c.vdem_polyarchy100##c.vdem_polyarchy100  
log_gdp_maddison log_neighbor_bd_merge neighbor_neighbor_cd log_n_refugee polyarchy100_neighbor conflict_ucdp2016 growth_maddison
i.ccode i.a_year, cluster(ccode) ; 
#delimit cr; 

